﻿using Microsoft.AspNetCore.Mvc;
using NuGet.Protocol.Core.Types;
using System.Collections.Generic;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using WMS.BasicData.Clients;
using WMS.BasicData.ProductDetails;
using WMS.BasicData.ProductDetails.DTO;

namespace WMS.Web.Controllers.BasicData.ProductDetails
{
    public class ProductDetailController : Controller
    {
        private readonly IProductDetailsService productDetailsService;


        public ProductDetailController(IProductDetailsService productDetailsService)
        {
            this.productDetailsService = productDetailsService;
           
        }


        #region 控制器
        /// <summary>
        /// 分页查询商品明细
        /// </summary>
        [HttpGet]
        public async Task<JsonResult> ShowProductDetails(int page, int limit, int belongsOwner, string? productName)
        {
           var pageData=await productDetailsService.ShowProductDetails(page, limit, belongsOwner, productName);
            return Json(new { data = pageData.Queryable, code = 0, count = pageData.CurrentPage });
        }

        /// <summary>
        /// 创建商品明细
        /// </summary>
        [HttpPost]
        public async Task<int> CreatePrdouctDetails(ProductDetail createProductDetailsDto)
        {
          int result=await productDetailsService.CreatePrdouctDetails(createProductDetailsDto);
            return result;
        }

        /// <summary>
        /// 删除商品明细
        /// </summary>
        [HttpPost]
        public async Task<int> DeleteProductDetails(int id)
        {
           return await productDetailsService.DeleteProductDetails(id);
        }

        /// <summary>
        /// 查看商品明细
        /// </summary>
        /// <param name="id"></param>
        [HttpGet]
        public async Task<CUProductDetailsDto> GetProductDetails(int id)
        {
          var productDetail = await productDetailsService.GetProductDetails(id);
            return productDetail;
        }

        /// <summary>
        /// 更新商品明细
        /// </summary>
        /// <param name="id"></param>
        [HttpPost]
        public async Task<int> UpdateProductDetails(CUProductDetailsDto productDTO)
        {
           int result=await productDetailsService.UpdateProductDetails(productDTO);
            return result;
        }

        //绑定客户名称
        [HttpGet]
        public async Task<List<WMS.BasicData.Clients.Client>> BindClientName()
        {
           var clientList = await productDetailsService.BindClientName();
           return clientList;
        }


        //批量删除商品明细
        [HttpPost]
        public async Task<int> BulkDeleteProductDetails(string array)
        {
            return await productDetailsService.BulkDeleteProductDetails(array);
        }


        #endregion





        #region 视图

        /// <summary>
        /// 显示商品明细
        /// </summary>
        /// <returns></returns>
        public IActionResult ShowProductDetail()
        {
            return View();
        }

        /// <summary>
        /// 创建商品明细
        /// </summary>
        /// <returns></returns>
        public IActionResult CreateProductDetail()
        {
            return View();
        }

        /// <summary>
        /// 修改商品明细
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdateProductDetail()
        {
            ViewBag.id=Request.Query["id"].ToString();
            return View();
        }


        #endregion

    }
}
